// app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts import { NextRequest, NextResponse } from "next/server" import { getServerSession } from "next-auth" import { authOptions } from "@/app/api/auth/[...nextauth]/route" import { addVendorQuestion, getVendorQuestions, answerVendorQuestion } from "@/lib/tbe-last/vendor-tbe-service" interface Props { params: { sessionId: string } } // GET: 질문 목록 조회 export async function GET( request: NextRequest, { params }: Props ) { try { const session = await getServerSession(authOptions) if (!session?.user?.companyId) { return NextResponse.json( { error: "Unauthorized" }, { status: 401 } ) } const vendorId = typeof session.user.companyId === 'string' ? parseInt(session.user.companyId) : session.user.companyId const sessionId = parseInt(params.sessionId) const questions = await getVendorQuestions(sessionId, vendorId) return NextResponse.json(questions) } catch (error) { console.error("Get questions error:", error) return NextResponse.json( { error: "Failed to get questions" }, { status: 500 } ) } } // POST: 새 질문 추가 export async function POST( request: NextRequest, { params }: Props ) { try { const session = await getServerSession(authOptions) if (!session?.user?.companyId) { return NextResponse.json( { error: "Unauthorized" }, { status: 401 } ) } const vendorId = typeof session.user.companyId === 'string' ? parseInt(session.user.companyId) : session.user.companyId const sessionId = parseInt(params.sessionId) const body = await request.json() const question = await addVendorQuestion( sessionId, vendorId, { category: body.category || "general", question: body.question, priority: body.priority || "normal", status: "open" } ) return NextResponse.json(question) } catch (error) { console.error("Add question error:", error) return NextResponse.json( { error: "Failed to add question" }, { status: 500 } ) } } // PATCH: 질문에 답변 추가 (구매자용) export async function PATCH( request: NextRequest, { params }: Props ) { try { const session = await getServerSession(authOptions) if (!session?.user) { return NextResponse.json( { error: "Unauthorized" }, { status: 401 } ) } const sessionId = parseInt(params.sessionId) const body = await request.json() const { questionId, answer } = body if (!questionId || !answer) { return NextResponse.json( { error: "Question ID and answer are required" }, { status: 400 } ) } const result = await answerVendorQuestion(sessionId, questionId, answer) return NextResponse.json(result) } catch (error) { console.error("Answer question error:", error) return NextResponse.json( { error: "Failed to answer question" }, { status: 500 } ) } }